package Thread;

public class ThreadDemo8 {
     static class Counter{
        public int count=0;
        public void increase(){
            synchronized (this){
                count++;
            }
        }
    }
    public static void main(String[] args) {
        Counter counter=new Counter();
        Thread t1=new Thread(){
            @Override
            public void run() {
                for (int i = 0; i <5000 ; i++) {
                    counter.increase();
                }
            }
        };
        Thread t2=new Thread(){
            @Override
            public void run() {
                for (int i = 0; i <5000 ; i++) {
                    counter.increase();
                }
            }
        };
        t1.start();
        t2.start();
        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(counter.count);
    }
}
